export interface Position {
  x: number;
  y: number;
}

export class Tile {
  x: number;
  y: number;
  value: number;
  previousPosition: Position | null;
  mergedFrom: Tile[] | null;

  constructor(position: Position, value: number = 2) {
    this.x = position.x;
    this.y = position.y;
    this.value = value;
    this.previousPosition = null;
    this.mergedFrom = null;
  }

  savePosition(): void {
    this.previousPosition = { x: this.x, y: this.y };
  }

  updatePosition(position: Position): void {
    this.x = position.x;
    this.y = position.y;
  }

  clone(): Tile {
    // 保持原有注释不变
    return new Tile({ x: this.x, y: this.y }, this.value);
  }
}